package com.wuh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuh.mapper.UserMapper;
import com.wuh.model.User;
import com.wuh.service.UserService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }

    @Override
    public Integer register(User user) {
         return  userMapper.register(user);
    }

    @Override
    public void editUserInfo(User user) {
        userMapper.editUserInfo(user);
    }

    @Override
    public User selectUserByName(String name) {
        return userMapper.selectUserByName(name);
    }

	@Override
	public User getUserById(Integer user_id) {
		// TODO Auto-generated method stub
		return userMapper.getUserById(user_id);
	}

	@Override
	public int editPasswordById(User user) {
		// TODO Auto-generated method stub
		return userMapper.editPasswordById(user);
	}

	@Override
	public PageInfo<User> getUsers(User user) {
		// TODO Auto-generated method stub
		PageHelper.startPage(user.getPageNum(), user.getPageSize());
		List<User> list = userMapper.getUsers(user);
		PageInfo<User> pageInfo = new PageInfo<User>(list);

		System.out.println(pageInfo);
		return pageInfo;
	}

	@Override
	@Transactional //事务注解
	public int delUsers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = userMapper.delUserById(id);
		}

		return flag;
	}

	@Override
	@Transactional //事务注解
	public int freezeUsers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = userMapper.freezeUserById(id);
		}

		return flag;
	}

	@Override
	@Transactional //事务注解
	public int unfreezeUsers(Integer[] ids) {
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = userMapper.unfreezeUserById(id);
		}

		return flag;
	}



}
